/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mytv.backbean;

import com.mytv.entity.Config;
import com.mytv.service.ConfigService;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

    
/**
 *
 * @author Sirius
 */
@ManagedBean
@ViewScoped
public class ConfigBean extends BackBean {
    
    private Config path;
    private Config player;
    
    /**
     * Constructor of class
     */
    public ConfigBean() {
        path = getConfigService().getConfig(ConfigService.PATH);
        if(path == null) {
            path = new Config();
            path.setCode(ConfigService.PATH);
            path.setValue("");
            getConfigService().save(path);
        }
        player = getConfigService().getConfig(ConfigService.PLAYER);
        if(player == null) {
            player = new Config();
            player.setCode(ConfigService.PLAYER);
            player.setValue("");
            getConfigService().save(player);
        }
    }

    /**
     * Get config service from spring context
     * @return A spring config service
     */
    public ConfigService getConfigService() {
        return (ConfigService) getSpringBean(ConfigService.class);
    }

    /**
     * Save current config
     */
    public void save() {
        getConfigService().updateConfig(path);
        getConfigService().updateConfig(player);
    }

    /**
     * Get path configuration
     * @return 
     */
    public Config getPath() {
        return path;
    }
    
    /**
     * Get path of player
     * @return 
     */
    public Config getPlayer() {
        return player;
    }

}